<?php

namespace App\Model;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class Piece extends BaseModel
{
    public $table = 'piece';
    public $connection = 'api';

    /**
     * Created at 2021/11/15 11:07
     * @Author <yuxiang.zhu@asiainnovations.net>
     * @param Request $request
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public function getlist(Request $request)
    {
        $page = $request->get('page', 0);
        $limit = $request->get('limit', 10);
        $status = $request->get('status', '');

        $sql = DB::connection($this->connection)->table($this->table)->orderByDesc('id')
            ->select('*');
        if ($status != '') {
            $sql->where('status', $status);
        }

        return $sql->paginate($limit, $this->fields, 'page', $page);
    }

    /**
     * Created at 2021/11/15 11:07
     * @Author <yuxiang.zhu@asiainnovations.net>
     * @param $data
     * @return mixed
     */
    public function upsertPieceGoods($data)
    {
        return curl_request(getKkaudioApiUrl() . '/inner/piece/goods/upsertPieceGoods', $data, 'json', 'POST');
    }
}
